-- This file is part of the Fantasy Grounds Open Foundation Ruleset project. 
-- For the latest information, see http://www.fantasygrounds.com/
--
-- Copyright 2008 SmiteWorks Ltd.
--
-- This file is provided under the Open Game License version 1.0a
-- Refer to the license.html file for the full license text
--
-- All producers of work derived from this material are advised to
-- familiarize themselves with the license, and to take special
-- care in providing the definition of Product Identity (as specified
-- by the OGL) in their products.
--
-- All material submitted to the Open Foundation Ruleset project must
-- contain this notice in a manner applicable to the source file type.


function getLevel()
	return tonumber(string.sub(getDatabaseNode().getChild("...").getName(), 6));
end

function getCast()
	return castnode.getValue();
end

function getPrepared()
	if isSpontaneous() then
		return nil;
	end

	return preparednode.getValue();
end

function preparedChanged()
	windowlist.updateCounters();
end

function castChanged()
	windowlist.updateCounters();
end

function isSpontaneous()
	return spontaneitynode.getValue() ~= 0;
end

function onInit()
	preparednode = getDatabaseNode().createChild("prepared", "number");
	castnode = getDatabaseNode().createChild("cast", "number");

	preparednode.onUpdate = preparedChanged;
	castnode.onUpdate = castChanged;

	spontaneitynode = getDatabaseNode().createChild(".....spontaneous", "number");
	
	counter.updateSlots();
end